package com.gongye.courseselectionsystem.controller;

import com.gongye.courseselectionsystem.constants.ResultCodeEnum;
import com.gongye.courseselectionsystem.pojo.vo.ResultList;
import com.gongye.courseselectionsystem.service.QueryCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author baorongchuan
 */
@Slf4j
@RestController
@Api(tags = "选课详情查询接口")
@RequestMapping("/select")
public class QueryCourseController {
    @Resource
    private QueryCourseService queryCourseService;

    @ApiOperation(value = "每门课可选的老师", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/CourseVo", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultList optionalCourseVo() {
        try {
            return new ResultList(ResultCodeEnum.SUCCESS, queryCourseService.getCourseVo());
        } catch (Exception e) {
            return new ResultList(ResultCodeEnum.FAILED, e.getMessage());
        }
    }

    @ApiOperation(value = "查询已选课学生接口", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/all", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultList queryAll() {
        try {
            return new ResultList(ResultCodeEnum.SUCCESS, queryCourseService.queryAll());
        } catch (Exception e) {
            return new ResultList(ResultCodeEnum.FAILED, e.getMessage());
        }
    }

    @ApiImplicitParams
            ({@ApiImplicitParam(name = "studentNumber", value = "学生学号", required = true, paramType = "query")})
    @ApiOperation(value = "根据学生编号查询学生选课记录", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/byId", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultList queryChooseById(Integer studentNumber) {
        try {
            return queryCourseService.queryChooseById(studentNumber);
        } catch (Exception e) {
            return new ResultList(ResultCodeEnum.FAILED, e.getMessage());
        }
    }
}
